/**
 * 异步错误处理
 * @param xhr
 * @param textStatus
 * @param errorThrown
 */
function ajaxErrorHandler(xhr, textStatus, errorThrown) {
    // session失效
    if (xhr.status == 401) {
        window.location.reload();
    }
}

/**
 * 执行动画效果
 * @param element 元素
 * @param clazz 样式
 * @param callback 回调函数
 */
function startAnimation(element, clazz, callback) {
    $(element).addClass(clazz + ' animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
        $(this).removeClass(clazz + ' animated');
        if (callback != undefined) {
            callback();
        }
    });
}

/**
 *
 * @param x
 * @returns {*}
 */
function toDecimal2(x) {
    var f1 = parseFloat(x);
    if (isNaN(f1)) {
        return false;
    }
    var f2 = Math.round(x * 100) / 100;
    var s = f2.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + 2) {
        s += '0';
    }
    return s;
}

function bootboxConfirm(message, callback) {
    bootbox.confirm({
        title: "提示信息",
        message: message,
        buttons: {
            confirm: {
                label: '确&nbsp;&nbsp;认',
                className: 'btn-success'
            },
            cancel: {
                label: '取&nbsp;&nbsp;消',
                className: 'btn-danger'
            }
        },
        backdrop: true,
        callback: callback
    });
}

toastr.options = {
    "closeButton": false,
    "debug": false,
    "newestOnTop": false,
    "progressBar": true,
    "positionClass": "toast-top-right",
    "preventDuplicates": false,
    "onclick": null,
    "showDuration": "300",
    "hideDuration": "1000",
    "timeOut": "3000",
    "extendedTimeOut": "1000",
    "showEasing": "swing",
    "hideEasing": "linear",
    "showMethod": "fadeIn",
    "hideMethod": "fadeOut"
};